package com.luminary.demo.user.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.luminary.common.framework.dao.GenericDao;
import com.luminary.common.framework.service.impl.GenericServiceImpl;
import com.luminary.demo.user.dao.UserDao;
import com.luminary.demo.user.model.po.User;
import com.luminary.demo.user.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

@Service
public class UserServiceImpl extends GenericServiceImpl<User, Integer> implements UserService {

	@Autowired
	private UserDao userDao;
	
	@Override
	protected GenericDao<User, Integer> getGenericDao() {
		return this.userDao;
	}

	@HystrixCommand(
			commandKey="findByUsername",
			groupKey="UserGroup",
            threadPoolKey="findByUsernameThread",
            commandProperties = {
            	@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000"),
            	@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
                @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "10")
        }
	)
	public User findByUsername(String username) throws Exception {
		return userDao.selectByUsername(username);
	}

}